package com.xbongbong.sys.util;

import com.xbongbong.sys.domain.entity.DepartmentEntity;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * @author 吴峰
 * @date 2021/12/16 15:18
 */
public class UserUtil {


    public static Set<Long> getSubDepIdList(Long depId, List<DepartmentEntity> departmentList) {
        Set<Long> subDepIdList = new LinkedHashSet<>();
        DepartmentEntity department = null;

        for (DepartmentEntity entity : departmentList) {
            if (entity.getId().equals(depId)) {
                department = entity;
                break;
            }
        }

        if (department != null) {
            String router = department.getDepIdRouter();
            for (DepartmentEntity entity : departmentList) {
                if (entity.getDepIdRouter().contains(router)) {
                    subDepIdList.add(entity.getId());
                }
            }
        }

        if (subDepIdList.isEmpty()) {
            subDepIdList.add(depId);
        }

        return subDepIdList;
    }

}
